/*********************************************************************************
  *FileName:  nsuc16xx_wwdg.c
  *Author:    ChenJiehong
  *Version:   V1.0
  *Date:      2024-03-22
****************************************Includes***********************************/
#include "nsuc16xx_wwdg.h"


/***************************************Variables***********************************/



/***************************************Functions***********************************/

/**
  * @brief  Disable WWDG.                  
  * @param  None
  * @retval None
  */
void WWDG_Disable(void)
{
    SYSCTRL->SYSCFR_b.WWDGEN = 0x00;
}

/**
  * @brief  Enables WWDG.                  
  * @param  None
  * @retval None
  */
void WWDG_Enable(void)
{
    SYSCTRL->SYSCFR_b.WWDGEN = 0x0A;
}

/**
  * @brief  Sets the WWDG Clock Prescaler.
  * @param  WWDG_Prescaler: specifies the WWDG Prescaler.
  *   This parameter can be one of the following values:
  *     @arg WWDG_Prescaler_1: WWDG counter clock = (AUX)/1
  *     @arg WWDG_Prescaler_2: WWDG counter clock = (AUX)/2
  *     @arg WWDG_Prescaler_4: WWDG counter clock = (AUX)/4
  *     @arg WWDG_Prescaler_8: WWDG counter clock = (AUX)/8
  *     @arg WWDG_Prescaler_16: WWDG counter clock = (AUX)/16
  *     @arg WWDG_Prescaler_32: WWDG counter clock = (AUX)/32
  *     @arg WWDG_Prescaler_64: WWDG counter clock = (AUX/)/64
  *     @arg WWDG_Prescaler_128: WWDG counter clock = (AUX)/128
  * @retval None
  */
void WWDG_SetPrescaler(uint8_t WWDG_Prescaler)
{
    WWDG->WPCR_b.WDPD = WWDG_Prescaler;
}

/**
  * @brief  Sets the WWDG Wakeup Clock Prescaler.
  * @param  WWDG_Prescaler: specifies the WWDG Prescaler.
  *   This parameter can be one of the following values:
  *     @arg WWDG_Prescaler_1: WWDG counter clock = (AUX/256)/1
  *     @arg WWDG_Prescaler_2: WWDG counter clock = (AUX/256)/2
  *     @arg WWDG_Prescaler_4: WWDG counter clock = (AUX/256)/4
  *     @arg WWDG_Prescaler_8: WWDG counter clock = (AUX/256)/8
  *     @arg WWDG_Prescaler_16: WWDG counter clock = (AUX/256)/16
  *     @arg WWDG_Prescaler_32: WWDG counter clock = (AUX/256)/32
  *     @arg WWDG_Prescaler_64: WWDG counter clock = (AUX/256)/64
  *     @arg WWDG_Prescaler_128: WWDG counter clock = (AUX/256)/128
  * @retval None
  */
void WWDG_Set_WakeUpPrescaler(uint8_t WWDG_Prescaler)
{
    WWDG->WPCR_b.WKPD = WWDG_Prescaler;
}

/**
  * @brief  Sets the WWDG window value.
  * @param  WindowValue: specifies the window value to be compared to the downcounter.
  * @retval None
  */
void WWDG_SetWindowValue(uint8_t WindowValue)
{
    WWDG->WWVR_b.WWV = WindowValue;
}

/**
  * @brief  Sets the WWDG counter value.
  * @param  Counter: specifies the watchdog counter value.
  * @retval None
  */
void WWDG_SetCounter(uint8_t Counter)
{
    WWDG->WTVR_b.WTV = Counter;
}

/**
  * @brief  Gets the WWDG Busy Status.
  * @param  None
  * @retval Busy Status
  */
FlagStatus WWDG_GetStatus(void)
{
  return (FlagStatus)(WWDG->WSTR_b.BUSY);
}

/***************************************END OF FILE*********************************/
